package com.stylefeng.guns.rest.modular.controller;

import com.stylefeng.guns.common.dto.common.ResultData;
import com.stylefeng.guns.modular.system.bean.DictReq;
import com.stylefeng.guns.modular.system.service.IDictToCService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * Created by lyz on 2018/2/4.
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/api/dict")
@Api(value = "字典表相关接口", produces = "application/json")
public class DictController {


    @Autowired
    private IDictToCService dictService;

    /**
     * 查询字典表
     * @param req
     * @return
     */
    @PostMapping("/dictInf")
    @ApiOperation(value = "根据父ID获取字典信息")
    public ResultData<List<Map<String,Object>>> getDictByPId(@Valid @RequestBody DictReq req) {
        List<Map<String,Object>> result = dictService.getDictByPid(req);
        return ResultData.createResult(result);
    }

    /**
     * 查询字典表
     * @param req
     * @return
     */
    @PostMapping("/dictInfById")
    @ApiOperation(value = "根据ID获取字典信息")
    public ResultData<String> getDictById(@Valid @RequestBody DictReq req) {
        String result = dictService.getDictById(req);
        return ResultData.createResult(result);
    }
}
